#include "scenesubclass.h"
#include <QPainter>
#include <QDebug>
sceneSubClass::sceneSubClass()
{
    isDrawGrid=false;

}

void sceneSubClass::setDrawGrid(bool val)
{
    isDrawGrid=val;
}

void sceneSubClass::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
//    if(event->modifiers() & Qt::ShiftModifier)
//        event->setModifiers(Qt::ControlModifier);
    QGraphicsScene::mousePressEvent(event);
}

void sceneSubClass::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
{
    QGraphicsScene::mouseReleaseEvent(event);
}

void sceneSubClass::contextMenuEvent(QGraphicsSceneContextMenuEvent *event)
{
    QGraphicsScene::contextMenuEvent(event);
}

void sceneSubClass::drawBackground(QPainter *painter, const QRectF &rect)
{
    if(isDrawGrid)
    {
        const int gridSize = 100;

       qreal left = int(rect.left()) - (int(rect.left()) % gridSize);
       qreal top = int(rect.top()) - (int(rect.top()) % gridSize);

       QVarLengthArray<QLineF, 100> lines;

       for (qreal x = left; x < rect.right(); x += gridSize)
       lines.append(QLineF(x, rect.top(), x, rect.bottom()));
       for (qreal y = top; y < rect.bottom(); y += gridSize)
       lines.append(QLineF(rect.left(), y, rect.right(), y));

       qDebug() << lines.size();

       painter->setPen(QPen(QBrush(Qt::gray),1));
       painter->drawLines(lines.data(), lines.size());
    }
    else
        QGraphicsScene::drawBackground(painter,rect);
}
